unit uCon_NCM;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Formulario_Padrao_Consulta, DB, Provider, DBClient, Grids,
  DBGrids, StdCtrls, TFlatButtonUnit, Buttons, ExtCtrls, DBTables;

type
  TfrmCon_NCM = class(TFrmConsulta)
    edDescricao: TEdit;
    Label1: TLabel;
    dbg: TDBGrid;
    ds: TDataSource;
    CDS: TClientDataSet;
    dsp: TDataSetProvider;
    CDSMNCM_CODIGO: TStringField;
    CDSDESCRICAO: TStringField;
    CDSMNCM_ID_NCM: TFloatField;
    CDSMNCM_EXTIPI: TStringField;
    procedure dbgTitleClick(Column: TColumn);
    procedure edDescricaoChange(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure BtnFecharClick(Sender: TObject);
    procedure dbgDblClick(Sender: TObject);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    NCM_ID_NCM: string;
  end;

var
  frmCon_NCM: TfrmCon_NCM;

implementation

uses Dm, clsNCM;

{$R *.dfm}

procedure TfrmCon_NCM.dbgTitleClick(Column: TColumn);
begin
  inherited;
  CDS.IndexFieldNames := Column.FieldName;
end;

procedure TfrmCon_NCM.FazConsulta;
var
  tq: TQuery;
  NCM: TMERCADORIA_NCM;
begin
  try
    NCM := TMERCADORIA_NCM.Create;
    tq := TQuery.Create(DmInt);
    tq.DatabaseName := DmInt.Db.DatabaseName;
    NCM.Consultar(tq, edDescricao.Text);
  finally
    NCM.Free;
  end;
  dsp.DataSet := tq;
  CDS.Open;
  tq.Free;
end;

procedure TfrmCon_NCM.edDescricaoChange(Sender: TObject);
begin
  inherited;
  FazConsulta;
end;

procedure TfrmCon_NCM.FormActivate(Sender: TObject);
begin
  inherited;
  FazConsulta;
end;

procedure TfrmCon_NCM.BtnFecharClick(Sender: TObject);
begin
  inherited;
  NCM_ID_NCM := CDSMNCM_ID_NCM.AsString;
end;

procedure TfrmCon_NCM.dbgDblClick(Sender: TObject);
begin
  inherited;
  BtnFecharClick(Sender);
end;

end.

